package lesson12;

import java.util.*;

public class Test01 {
    public static void main(String[] args) {
        // ArrayList

        List arrayList = new ArrayList();
        arrayList.add(1);
        arrayList.add(10.5);
        arrayList.add("hello");
        arrayList.add("hello");
        arrayList.add(new Student("张三",20,"男"));

//        arrayList.remove(1);
//        arrayList.clear();
//        arrayList.add(0,"插入元素");
//        arrayList.set(2,"java");
//        System.out.println(arrayList.size());
//        for(int i = 0;i < arrayList.size();i++){
//            System.out.println(arrayList.get(i));
//        }

        List newList = arrayList.subList(1,3);
//        System.out.println(newList);
        // 将List集合转换为数组
        Object [] ary = newList.toArray();
//        System.out.println(ary.length);
        // 将数组转换为List集合
        List list1 = Arrays.asList(ary);
//        System.out.println(list1);

        // 使用Iterator迭代器循环集合
//        Iterator it = arrayList.iterator();
//        while(it.hasNext()){
//            System.out.println(it.next());
//        }

        // for - in/each 循环
//        for(Object obj : arrayList){
//            System.out.println(obj);
//        }

        // Set集合
//        HashSet set = new HashSet();
//        set.add(1);
//        set.add(10.5);
//        set.add("hello");
//        set.add(new Student("张三",20,"男"));
//        set.add(new String("hello"));
//        set.add(new Student("张三",25,"女"));

//        System.out.println(set.size());
//        Iterator it = set.iterator();
//        while(it.hasNext()){
//            System.out.println(it.next());
//        }
//        for(Object obj : set){
//            System.out.println(obj);
//        }

//        ArrayList newArrayList = new ArrayList();
//        newArrayList.addAll(set);
//        System.out.println(newArrayList);
//        System.out.println(newArrayList.get(0));

        // Map：键值对集合
        HashMap map = new HashMap();
        map.put("name","张三");
        map.put("age",20);
        map.put("gender","男");
        map.put("phone","13800000000");
        map.put("name1","张三");

        System.out.println(map.size());
        System.out.println(map.get("gender"));
        System.out.println(map.get("phone"));
        System.out.println(map.get("name"));

        // 把Map中所有的键取出来循环
        for(Object key : map.keySet()){
            System.out.println(key + " " + map.get(key));
        }
        // 把Map中所有的值取出来循环
        for(Object value : map.values()){
            System.out.println(value);
        }

    }
}
